package com.feihong.txgw.tx_model;

import android.text.TextUtils;

import com.feihong.txgw.inter.contract.kaika.IKaikaSelectPhoneNumContract;
import com.feihong.txgw.json.kaika.Menu;
import com.feihong.txgw.utils.UserLoginInfo;
import com.feihong.txgw.utils.helper.RxHelper;
import com.feihong.txgw.utils.manage.RetrofitManager;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import io.reactivex.Observable;


/**
 * @Author wangziheng
 * @ProjectName txgw_app
 * @ClassName KaikaSelectPhoneNumMainModel
 * @package com.feihong.txgw.tx_model
 * @data 2018/5/4 15:29
 * @Describe
 * @Change
 */
public class KaikaSelectPhoneNumMainModel implements IKaikaSelectPhoneNumContract.IKaikaSelectPhoneNumMainModel{

    public static KaikaSelectPhoneNumMainModel create(){
        return new KaikaSelectPhoneNumMainModel();
    }
    @Override
    public Observable<Menu> getPhoneNumMenu(String iccid) {
        return RetrofitManager.getInstance().getKaikaPhoneNumMenu(iccid).compose(RxHelper.<Menu>rxSchedulerHelper());
    }

    @Override
    public Observable getPhoneNumList(String iccid, String pageNum, String phoneNum, String packageID,Map<String,String> params) {
        Map<String,String> mParams = new HashMap<>();
        mParams.put("iccid", TextUtils.isEmpty(iccid) ? "" : iccid);
        mParams.put("p", pageNum);
        mParams.put("phonenum", TextUtils.isEmpty(phoneNum) ? "" : phoneNum);
        mParams.put("spec_id",TextUtils.isEmpty(packageID) ? "" : packageID);
        mParams.put("citycode", UserLoginInfo.getUserCityInfo().getCityCode());
        if (params.size() > 0) {
            Iterator<Map.Entry<String, String>> entryIterator = params.entrySet().iterator();
            while (entryIterator.hasNext()) {
                Map.Entry<String, String> item = entryIterator.next();
                mParams.put(item.getKey(), item.getValue());
            }
        }
        return RetrofitManager.getInstance().getKaikaPhoneNumList(mParams).compose(RxHelper.rxSchedulerHelper());
    }
}
